
var com = new CommonUtil();
$(function(){
	var Info = {
		init:function () {
			this.bindClick();
			this.loadData();
		},
		bindClick:function(){
			var e = this;
			// 表单提交
			// /receipt/save
			$("#infoSubmit").click(function (){
				var params = $("#orderForm").serializeArray();
				console.log("表单数据：",params)
				var values = {};
				for(var p in params ){
					var name = params[p].name;
					var value = params[p].value;
					values[name] = value;
				}
				e.ajaxRequst(com.basePath()+"/receipt/save","post",values,e.goToExamine);
			});
		},
		loadData: function (data) {
			$("#updateDelay").val(com.dateFormat(new Date(),"yyyy-MM-dd hh:mm:ss"));
		},
		goToExamine(){
			window.location.href = "toCheckExp";
		},
		/**
		 * 发起ajax请求
		 */
		ajaxRequst:function(url,type,data,call,obj){
			var o = this;
			if(!url || !data){
				return;
			}
			$.ajax({
				url:url,
				type: type,
				dataType: "json",
				data: JSON.stringify(data),
//                async: false,
               contentType:'application/json;charset=UTF-8',
               // contentType:'application/x-www-form-urlencoded;charset=UTF-8',
				success: function(data) {
//                	var data = eval("("+data+")");//转换为json对象
					if(data.status=="200" ) {
						if ($.isFunction(call)) {
							call(obj == undefined ? data.list : obj);
						}
					} else if(data.code=="200"){
						if ($.isFunction(call)) {
							call(obj == undefined ? null: obj, data.data.receiptData );
						}
					} else {
						//信息框
						layer.open({
							content: data.message
							,btn: '确定'
						});
					}
				},
				error: function() {
					//信息框
					layer.open({
						content: '数据出现问题,请重试'
						,btn: '确定'
					});
				}
			});
//        	return false; // 阻止表单自动提交事件
		}
	}
	Info.init();
})
